import request, { type Res } from '@/utils/request'

interface DataType {
  label: string
  value: number
  type?:number
  remark?:string
}

function rawListReqToCommonListReq(
  rawReq: Promise<Res<any[]>>,
  callback: (data: any) => any
): Promise<Res<DataType[]>> {
  return rawReq.then((data) => {
    data.data = data.data.map(callback)
    return data
  })
}

// 所有游戏
export function getGameTotal() {
  return rawListReqToCommonListReq(
    request({
      url: '/v1/admin/gameList',
      method: 'get',
      params: {}
    }),
    (v) => ({ label: v.game_name, value: v.game_id, type: v.game_type })
  )
}

// 所有币种
export function getCurrencyTotal() {
  return rawListReqToCommonListReq(
    request({
      url: '/v1/admin/system/allCurrencyList',
      method: 'get',
      params: {}
    }),
    (v) => ({ label: v.name, value: v.id, type: v.symbol, remark:v.remark })
  )
}

// 所有总代
export function getOperatorTotal() {
  return rawListReqToCommonListReq(
    request({
      url: '/v1/admin/system/allOperatorList',
      method: 'get',
      params: {}
    }),
    (v) => ({ label: v.operator_name, value: v.id, type:v.is_multi_currency })
  )
}

// 获取总代下-所有商户
export function getCommercialTotal(params: { operated_id: number }) {
  return rawListReqToCommonListReq(
    request({
      url: '/v1/admin/system/allAgentList',
      method: 'get',
      params: params
    }),
    (v) => ({ label: v.agent_name, value: v.id, type:v.agent_type })
  )
}

// 所有商户
export function getAgentTotal() {
  return rawListReqToCommonListReq(
    request({
      url: '/v1/user/getAgentData',
      method: 'get',
      params: {}
    }),
    (v) => ({ label: v.agent_name, value: v.agent_id, type:v.agent_type })
  )
}
// 所有商户货币
export function getAgentCurrencyTotal() {
  return rawListReqToCommonListReq(
    request({
      url: '/v1/user/getAgentData',
      method: 'get',
      params: {}
    }),
    (v) => ({ label: v.currency_id, value: v.agent_id })
  )
}

// 语言列表
export function getLanguageList() {
  return rawListReqToCommonListReq(
    request({
      url: '/v1/admin/system/languageList',
      method: 'get',
      params: {}
    }),
    (v) => ({ label: v.name, value: v.id })
  )
}
